<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>设备</title>
    <meta name="keywords" content="设备">
    <meta name="description" content="设备">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="<?= base_url('assets/css/bootstrap.min.css?v=3.3.6') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/font-awesome.css?v=4.4.0') ?>" rel="stylesheet">

    <!-- Data Tables -->
    <link href="<?= base_url('assets/css/plugins/dataTables/dataTables.bootstrap.css') ?>" rel="stylesheet">

    <link href="<?= base_url('assets/css/animate.css') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/style.css?v=4.1.0') ?>" rel="stylesheet">

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>设备 <small>查找 SN , 有用户者ID</small></h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="table_data_tables.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
<!--                            <ul class="dropdown-menu dropdown-user">-->
<!--                                <li><a href="table_data_tables.html#">选项1</a>-->
<!--                                </li>-->
<!--                                <li><a href="table_data_tables.html#">选项2</a>-->
<!--                                </li>-->
<!--                            </ul>-->
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <table class="table table-striped table-bordered table-hover dataTables-example">
                                <thead>
                                </thead>
                                <tbody>
                                </tbody>
                        </table>

                    </div>
                </div>
            </div>
        </div>

    </div>

    <!-- 全局js -->


    <?php include "include/admin_foot_script.php" ?>

    <!-- Data Tables -->
    <script src="<?= base_url('assets/js/plugins/dataTables/jquery.dataTables.js') ?>"></script>
    <script src="<?= base_url('assets/js/plugins/dataTables/dataTables.bootstrap.js') ?>"></script>
    <link href="<?= base_url('assets/css/style.css?v=4.1.0') ?>" rel="stylesheet">
    <!-- 自定义js -->
    <script src="<?= base_url('assets/js/content.js?v=1.0.0') ?>"></script>

    <script src="<?= base_url('assets/js/plugins/layer/layer.min.js') ?>"></script>


    <!-- Page-Level Scripts -->
    <script>


//        $.fn.dataTable.ext.search.push(
//            function( settings, data, dataIndex ) {
//                var min = parseInt( $('#min').val(), 10 );
//                var max = parseInt( $('#max').val(), 10 );
//                var age = parseFloat( data[3] ) || 0; // use data for the age column
//
//                if ( ( isNaN( min ) && isNaN( max ) ) ||
//                    ( isNaN( min ) && age <= max ) ||
//                    ( min <= age   && isNaN( max ) ) ||
//                    ( min <= age   && age <= max ) )
//                {
//                    return true;
//                }
//                return false;
//            }
//        );


var table ;
        $(document).ready(function () {
             table = $('.dataTables-example').dataTable({
                "processing": true,
                "serverSide": true,
                "searching": true,
                "columns": [
                    { "title": "序号", "orderable": false, "data": null },
                    { "title": "用户I" , "orderable": false, "data": "user_id"},
                    { "title": "用户加密ID" , "orderable": false, "data": "en_user_id"},
                    { "title": "SN", "orderable": false, "data": "sn" },
                    { "title": "头像", "orderable": false, "data": "pic", "render":function(data, type, row, meta) {
                        return "<img src = "+data+"  width='50px' height='50px' onerror='this.src=\"<?= base_url('assets/img/mynt-icon.png') ?>\" '  />";
                    } },
                    { "title": "名称", "orderable": false, "data": "name" },
                    { "title": "类型" , "orderable": false, "data": "mynt_type", "render":function(data, type, row, meta) {

                        if (data == 1) {
                            return '<span class="label label-primary">GPS</span>';
                        }

                        if (data == 0) {
                            return '<span class="label label-info">MYNT</span>';
                        }

                        if (data == 2) {
                            return '<span class="label label-primary">ES</span>';
                        }

                    }},
                    { "title": "hardware", "orderable": false, "data": "hardware_version" },
                    { "title": "softward", "orderable": false, "data": "software_version" },
                    { "title": "mac地址", "orderable": false, "data": "mac" },
                    { "title": "绑定时间", "data": "create_time" },
                    { "title": "操作" , "orderable": false, "data": "device_id"}
                ],

                columnDefs:[{
                    targets: 11,
                    render: function (data, type, row, meta) {
                        return '<button type="button" class="btn btn-primary btn-xs" onclick="detail('+data+')">详细</button>&nbsp;&nbsp;&nbsp; <button type="button"  class="btn btn-danger btn-xs" onclick="unBind(\''+ row.sn + '\',' + data+')">解绑</button>';
                    }
                },

                ],

            "ajax": {
                "url": "<?= base_url('device/data') ?>",
                    "data": function ( d ) {
                   // d.p1 = "xxx";

                        d.device_type = <?= $data['device_type']?>
                },
                "type": "POST"
            },

                "fnDrawCallback": function() {
                    var api = this.api();
                    var startIndex = api.context[0]._iDisplayStart;//获取到本页开始的条数
                    api.column(0).nodes().each(function (cell, i) {
                        cell.innerHTML = startIndex + i + 1;
                    });
                }

            });

        });


       function detail(id) {
           toastr.warning("开发中...", '提示');
       }

        function unBind(sn, id) {

            parent.layer.confirm('确认要解绑'+sn+'设备吗？', {
                btn: ['确认','取消'], //按钮
                shade: true, //不显示遮罩,
                shadeClose: true
            }, function(index){

                $.post("<?= base_url("device/unbind") ?>", {"deviceId": id} ,function (res) {
                    parent.layer.close(index);
                    if (res.code == 200) {
                        table.api().ajax.reload();
                        toastr.success("解绑成功", '提示');

                    } else {
                        toastr.error(res.msg, '提示');
                        alert(res.msg);
                    }

                }, "json");




            }, function(){
                //parent.layer.msg('奇葩么么哒', {shift: 6});
            });
        }
    </script>



</body>

</html>
